package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.POJO.Food;
import org.apache.ibatis.annotations.*;
import java.util.HashMap;

public interface FoodMapper {

    //删除
    @Delete("DELETE FROM t_food WHERE foodId = #{foodId}")
    void deleteFood_id4food_checkgroup(@Param("foodId") Integer foodId);

    @Delete("DELETE FROM t_food WHERE foodId=#{foodId}")
    void deleteFoodById(Integer foodId);

    @Insert("insert into t_food values (null,#{code},#{foodName},#{foodType},#{foodJK},#{foodProtein},#{foodFat},#{foodWater},#{foodKcal},#{gxy},#{tlb},#{gxb},#{ncz},#{xnxgjb},#{gxz},#{fp},#{tf},#{explain})")
    void addfood(Food food);

    @Insert("insert into t_food (food_id,checkgroup_id) values (#{food_id},#{checkgroup_id})")
    void addfoodAndcheckgroup(HashMap<String, Integer> map);

    //分页
    @Select("<script>select * from t_food " +
            "<if test=\"value != null and value.length > 0\"> " +
            "where code = #{value} or foodName like concat('%',#{value},'%')  " +
            "</if>" +
            "</script>")
    Page<Food> findPage(String queryString);

    @Select("select * from t_food where foodId = #{id}")
    Food findFoodByid(Integer id);

    /*
    UPDATE t_food
    <set>
       <if test="code != null">
       code = #{code},
       </if>
       <if test="foodName != null">
       foodName = #{foodName},
       </if>
       <if test="foodType != null">
       foodType = #{foodType},
       </if>
       <if test="foodJK != null">
       foodJK = #{foodJK},
       </if>
       <if test="foodProtein != null">
       foodProtein = #{foodProtein},
       </if>
       <if test="foodFat != null">
       foodFat = #{foodFat},
       </if>
       <if test="foodWater != null">
       foodWater = #{foodWater},
       </if>
       <if test="foodKcal != null">
       foodKcal = #{foodKcal},
       </if>
       <if test="gxy != null">
       gxy = #{gxy},
       </if>
       <if test="tlb != null">
       tlb = #{tlb},
       </if>
       <if test="gxb != null">
       gxb = #{gxb},
       </if>
       <if test="ncz != null">
       ncz = #{ncz},
       </if>
       <if test="xnxgjb != null">
       xnxgjb = #{xnxgjb},
       </if>
       <if test="gxz != null">
       gxz = #{gxz},
       </if>
       <if test="fp != null">
       fp = #{fp},
       </if>
       <if test="tf != null">
       tf = #{tf},
       </if>
        <if test="explain != null">
       explain = #{explain},
       </if>
    </set>
     where foodId = #{foodId}
    */
    @Update("<script> UPDATE t_food\n" +
            "    <set>\n" +
            "       <if test=\"code != null\">\n" +
            "       code = #{code},\n" +
            "       </if>\n" +
            "       <if test=\"foodName != null\">\n" +
            "       foodName = #{foodName},\n" +
            "       </if>\n" +
            "       <if test=\"foodType != null\">\n" +
            "       foodType = #{foodType},\n" +
            "       </if>\n" +
            "       <if test=\"foodJK != null\">\n" +
            "       foodJK = #{foodJK},\n" +
            "       </if>\n" +
            "       <if test=\"foodProtein != null\">\n" +
            "       foodProtein = #{foodProtein},\n" +
            "       </if>\n" +
            "       <if test=\"foodFat != null\">\n" +
            "       foodFat = #{foodFat},\n" +
            "       </if>\n" +
            "       <if test=\"foodWater != null\">\n" +
            "       foodWater = #{foodWater},\n" +
            "       </if>\n" +
            "       <if test=\"foodKcal != null\">\n" +
            "       foodKcal = #{foodKcal},\n" +
            "       </if>\n" +
            "       <if test=\"gxy != null\">\n" +
            "       gxy = #{gxy},\n" +
            "       </if>\n" +
            "       <if test=\"tlb != null\">\n" +
            "       tlb = #{tlb},\n" +
            "       </if>\n" +
            "       <if test=\"gxb != null\">\n" +
            "       gxb = #{gxb},\n" +
            "       </if>\n" +
            "       <if test=\"ncz != null\">\n" +
            "       ncz = #{ncz},\n" +
            "       </if>\n" +
            "       <if test=\"xnxgjb != null\">\n" +
            "       xnxgjb = #{xnxgjb},\n" +
            "       </if>\n" +
            "       <if test=\"gxz != null\">\n" +
            "       gxz = #{gxz},\n" +
            "       </if>\n" +
            "       <if test=\"fp != null\">\n" +
            "       fp = #{fp},\n" +
            "       </if>\n" +
            "       <if test=\"tf != null\">\n" +
            "       tf = #{tf},\n" +
            "       </if>\n" +
            "        <if test=\"explain != null\">\n" +
            "       explain = #{explain},\n" +
            "       </if>\n" +
            "    </set>\n" +
            "     where foodId = #{foodId}" +
            "</script>")
    Long update(Food food);

    //void add(Food food);
}
